package com.dzp.simpleSyslogServer.thread;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dzp.simpleSyslogServer.syslog.SyslogServer_dzp;
import com.dzp.simpleSyslogServer.util.CommonUtil;

public class TaskThread extends Thread {
	private static Logger logger = LoggerFactory.getLogger(TaskThread.class);

	private JSONObject params;

	public TaskThread(JSONObject params) {
		this.params = params;
	}

	public JSONObject getParams() {
		return params;
	}

	@Override
	public void run() {
		// 当前线程相关参数
		String threadName = Thread.currentThread().getName();
		logger.debug("----开始执行：threadName = {},params = {}", threadName, params.toJSONString());
		try {
			/**
			 * 线程类型
			 */
			String type = params.getString("type");
			switch (type) {
			case "SyslogServer": {
				String protocol = params.getString("protocol");
				Integer port = params.getInteger("port");
				SyslogServer_dzp.start(protocol, port);
				break;
			}

			default:
				logger.info("----TaskThread not support type = {}", type);
				break;
			}

		} catch (Exception e) {
			logger.error("-----任务执行异常- params = {} , error = {}", JSON.toJSONString(params),
					CommonUtil.getExceptionTrace(e));
		}
	}
}
